<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<style type="text/css"> 
.msg{float:left; line-height:1.5em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style> 
<s:url value="/images" var="imgPath"/>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />

<script language="javascript">
	$().ready( function() {
		$("#basePrice").numeric({allow:"."});
		$('#startDate').datepick({minDate: null, showOn: 'both', 
	    	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		$('#endDate').datepick({minDate: new Date(), showOn: 'both', 
		   	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,beforeShow:customRange,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		function customRange (){
			var startDt = $('#startDate').val(); //起始日
			var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
			return {minDate:endDt}; 
		}
    	$("#saveData").click(function(){
        	
        	if ( validateData() )
        		$("#formObj").submit();
    	});    	
    	if("${checkResult}" == "period_duplicate"){
			$("#errMsg").html('日期区间重复，请重新输入日期区间');
			$("#errMsg").show();
		}
	});	
	function validateData(){
		var isCorrect = true;		
		if ( $("#startDate").val() == "" ){
			alert("请输入期间 起");
			isCorrect = false;
		}
		if ( $("#endDate").val() == "" ){
			alert("请输入期间 迄");
			isCorrect = false;
		}
		if ( $("#basePrice").val() == "" ){
			alert("请输入满额购金额条件");
			isCorrect = false;
		}
		return isCorrect;
	}

</script>
<s:actionerror/>
<s:actionmessage/>
<s:fielderror />
<s:form action="save.do" method="post" id="formObj" >
<h1>满额购条件设定:</h1>
<p><b>期间 起：</b>
<input type="hidden" name="settingId" id="settingId" value="${settingId }"/>
<input type="text" name="startDate" id="startDate" value="${startDate}" size="10" readonly="readonly"/>
<select id="startTime" name="startTime">			
<c:forEach begin="0" end="23" var="t1">
	<c:if test="${t1<10}">
	<c:set value="0${t1}:00" var="sTime"></c:set>
	</c:if>
	<c:if test="${t1>=10}">
	<c:set value="${t1}:00" var="sTime"></c:set>
	</c:if>
	<option value="${sTime}" <c:if test="${sTime==startTime }">selected</c:if>>${sTime}</option>
</c:forEach>
</select>
</p>
<p><b>期间 迄：</b>

<input type="text" name="endDate" id="endDate" value="${endDate}" size="10" readonly="readonly"/>
<select id="endTime" name="endTime">			
<c:forEach begin="0" end="23" var="t2">	
	<c:if test="${t2<10}">
	<c:set value="0${t2}:59" var="eTime"></c:set>
	</c:if>
	<c:if test="${t2>=10}">
	<c:set value="${t2}:59" var="eTime"></c:set>
	</c:if>
	
	<option value="${eTime}" <c:if test="${eTime==endTime }">selected</c:if>>${eTime}</option>
</c:forEach>
</select>
</p>
<p><b>满额购金额条件：</b>
<input type="text" id="basePrice" name="basePrice" value="${basePrice}"/></p>
<span class="txt-rd">【※满额购金额小数点1位数后无条件舍去】</span>
<span id="errMsg" class="msg rn" style="display:none"></span>
<div class="f-link">
	<a href="#" id="saveData">存档</a>
</div>
</s:form>
